import UICore from "../../../../Core/Res/UICore";
import * as fgui from "fairygui-cc";
import AbstractUIWindow from "../../window/AbstractUIWindow";
import AudioManager from "../../../../Core/Audio/AudioManager";
import SdkTool from "../../../../Core/Sdk/SdkTool";
import { ViewManager } from "../../base/ViewManager";
import { GameModels } from "../../socket/GameModels";
import EventMgr from "../../../../Core/Event/EventMgr";
import ModuleWindow from "../../window/ModuleWindow";
import WindowObject from "../../window/WindowObject";
import { common } from "../../../proto/protoCmd";

export class RoomInfoWindow extends AbstractUIWindow {
    private playerList: fgui.GList;
    private roomId: fgui.GTextField;
    protected getResList(): Array<string> {
        return [`Plane`];
    }
    protected onInit(): void {
        this._view = UICore.createObject("Plane", "RoomInfoWindow").asCom;
    }
    protected onShow(): void {
        this.roomId.text = `房间号:${GameModels.lobby.RoomId}`;
        this.playerList.itemRenderer = this.onplayerList.bind(this);
        if (GameModels.lobby.Players.length > 0) {
            this.playerList.numItems = GameModels.lobby.Players.length;
            return;
        }
        const me: fgui.GComponent = this.playerList.getChildAt(0);
        const other: fgui.GComponent = this.playerList.getChildAt(1);
        me.getChild(`nameTxt`).text = `玩家名:${GameModels.info.playerInfo.NickName}`;
        me.getChild(`descTxt`).text = `这显示战绩`;
        if (GameModels.lobby.OtherPlayer) {
            other.getChild(`nameTxt`).text = `玩家名:${GameModels.lobby.OtherPlayer.NickName}`;
            other.getChild(`descTxt`).text = `这显示战绩`;
        } else {
            other.getChild(`nameTxt`).text = ``;
            other.getChild(`descTxt`).text = ``;
        }
    }
    private onplayerList(index: number, item: fgui.GComponent): void {
        const info: common.IGamePlayerInfo = GameModels.lobby.Players[index];
        item.getChild(`nameTxt`).text = `玩家名:${info.NickName}`;
        item.getChild(`descTxt`).text = `这显示战绩`;
    }
}